package sismed.gui.comando;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sismed.exception.DAOException;
import sismed.negocio.fachada.Fachada;
import sismed.negocio.modelo.Exame;

public class ComandoCarregarExamesFarmaceutico extends ComandoGenerico {

	@Override
	public void executar(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		if( request.getSession().getAttribute("tipoUsuario").equals( null ) )				
			response.sendRedirect("login.jsp");
		else {
		System.out.println("ENTREI NO CARREGAR");
			Fachada fachada = Fachada.getInstance();
			int id = Integer.parseInt( request.getSession().getAttribute( "id" ).toString());
			List<Exame> listaExames = null;
			try {
				listaExames = fachada.recuperarExamesPorFarmaceutico( id );
			} catch (DAOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			request.setAttribute( "ListaExames", listaExames );
			try {		
				request.getRequestDispatcher("FarmaceuticoVisualizarExames.jsp").forward( request, response );	
			}
			catch ( Exception e ) {
				response.sendRedirect("erro.jsp?msgerro=Erro ao recuperar mensagens.");	
			}
		}
	}	
}
